<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<%
	String path = request.getContextPath();
%>

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>CP Info List</title>
		
		<script src="<%=path%>/static/js/jquery-1.6.1.min.js" type="text/javascript"></script>
		<script src="<spring:url value="/static/js/jquery.easyui.min.js" />" type="text/javascript" ></script>
		<link rel="stylesheet" type="text/css" href="<%=path%>/static/css/themes/default/easyui.css">
		<link href="<%=path%>/static/css/themes/icon.css" rel="stylesheet" type="text/css" />
		

	<script type="text/javascript">
	
	function saveOrUpdate(){
		var r = $('#cpinfoForm').form('validate');
		if (!r) {
			return false;
		}
		$.messager.progress({
            title:'Please wait',
            msg:'Data is processing ...',
            text:"Loading..."
        });
		$.post("saveOrUpdate", $("#cpinfoForm").serializeArray(),
				function(data) {
					$('#MyPopWindow').window('close');
					$.messager.progress('close');
					$('#infoListTable').datagrid('reload');
					$.messager.alert('提示', data.mes, 'info');
				});
	}
	
			jQuery(function($){
				$('#infoListTable').datagrid({
					title:'CP Info List',
					method:'post',
					iconCls:'icon-edit',
					fit:true,
					fitColumns: true,
					striped: true,
					singleSelect: true,
					url:"cpinfoList",
					idField:'id',
					rownumbers:true,
					checkOnSelect:false,
					columns:[[
						{field:'id',title:'ID',width:10
						},
						{field:'name',title:'CP全称',width:20},
						{field:'shortName',title:'CP简称',width:15},
						{field:'address',title:'地址',width:20},
						{field:'personName',title:'接口人姓名',width:10},
						{field:'tel',title:'电话号码',width:10},
						{field:'mail',title:'电子邮箱',width:10},
						{field:'cpTypeName',title:'CP类型',width:10},
						{field:'creatTime',title:'生成时间',width:10}
					]],
					toolbar:[{
						text:'新增',
						iconCls:'icon-add',
						handler:function(){
							addrow();
						}
					},'-',{
						text:'更新',
						iconCls:'icon-edit',
						handler:function(){
							updaterow();
						}
					},'-'],
					onLoadSuccess:function(data){
						$('#infoListTable').datagrid('clearSelections');
						$('#infoListTable').datagrid('clearChecked');
					}
				});
		    });
			
        	$.ajaxSetup({
					global : false,
					type : "POST",
					complete : function(XMLHttpRequest, textStatus) {
						var data = XMLHttpRequest.responseText;
						var redirect=window.top.location.host+"/YouLeCloud/login";
						if (data=="timeout") {
							if (window.top != window.self) {
							   window.top.location.href="${redirect}";
							   return;
							   }
						}
					}
				});
        
				

        	function addrow(){
        		$("#MyPopWindow").window({
          			title:'增加信息',
          			href:'popWindow',
          			width:400,
          			height:320,
          			onLoad: function(){
          				//$('#form').form('clear');
          			}
          			
          		});
        	}
        	
        	function updaterow(){
        		var rows = $('#infoListTable').datagrid('getSelections');
        		if(rows.length==0){
        			$.messager.alert('提示',"请选择你要更新的信息",'info');
        			return;
        		}
        		if(rows.length > 1){
        			$.messager.alert('提示',"只能选择一位进行更新",'info');
        			return;
        		}
        		$("#MyPopWindow").window({
          			title:'更新信息',
          			href:'popWindow',
          			width:400,
          			height:320,
          			onLoad: function(){
          				$("#cpinfoForm").form('load', rows[0]);
          			}
          		});
        	}
        	
			
			function reloadOrderDataGrid() {
				var params = $('#infoListTable').datagrid('options').queryParams;
				var fields =$('#queryForm').serializeArray();
				$.each( fields, function(i, field){
					params[field.name] = field.value;
				});
				$('#infoListTable').datagrid('reload');
			}
			
                var height = window.screen.height-250;  
                var width = window.screen.width;  
                var leftW = 300;  
                if(width>1200){  
                   leftW = 400;  
                }else if(width>1000){  
                   leftW = 350;
                }else {  
                   leftW = 100;
                }  
			
			function openViewFrame(o) {
				$('#idDetailView').html("");
                $('#idDetailView').window('open');
                
                
				$('#idDetailView').append("<div id='idDivWait' style='position:absolute;left:0;width:100%;height:"+height+"px;top:20px;background:#E0ECFF;opacity:0.8;filter:alpha(opacity=80);'>"
				+"<div style='position:absolute;  cursor1:wait;left:40%; top:40%;width:auto;height:16px;padding:12px 5px 10px 30px;"
				+"background:#fff url(../static/css/themes/default/images/loading.gif) no-repeat scroll 5px 10px;border:2px solid #ccc;color:#000;'>"
				+"Loading... Please wait..."
				+"</div></div>");
				
				$('#idDetailView').append('<iframe id="idDetailViewiFrame" frameborder="0" style="width:100%;height:100%;"></iframe>');
				
				$('#idDetailViewiFrame').attr("src",$(o).attr("srcurl"));
            }
			
			
			function reloadDataGrid() {
				var params = $('#infoListTable').datagrid('options').queryParams;
				var fields =$('#queryForm').serializeArray();
				$.each( fields, function(i, field){
					params[field.name] = field.value;
				});
				$('#infoListTable').datagrid('reload');
			}
			
			function searchInfo() {
				reloadDataGrid();
			}
			
			
			
	</script>
		
	</head>


	<body class="easyui-layout" style="height: 100%">
	
		<div data-options="region:'north'" 
			style="padding: 1px 0 1px 1px; height: 80px;"
			title="查询">
			<form id="queryForm" style="margin:5;text-align: center;">
			<table width="100%">
				<tr>
					<td>
						CP 名称 &nbsp;&nbsp;&nbsp;&nbsp;<input name="name" style="width: 150">
					</td>
					<td>
						<a href="#" onclick="searchInfo();" class="easyui-linkbutton" iconCls="icon-search"><div style="width: 30px;float: left;">查询</div></a>
					</td>
				</tr>
			</table>
			</form>
		</div>
	
		<div data-options="region:'center'" style="padding:10; " id="tabdiv">
			<table id="infoListTable"></table>
		</div>
		
		<div id="idDetailView" title="Detail View"  class="easyui-window" data-options="closed:true,iconCls:'icon-save'" style="width:755px;height:440px;">
	 	</div> 
	 	<div id="MyPopWindow" modal="true" shadow="false" minimizable="false" cache="false" maximizable="false" collapsible="false" resizable="false" style="margin: 0px;padding: 0px;overflow: auto;"></div>
	</body>
